$(function () {
	
	//滚动到某个位置公司导航栏固定
	var companyNav = $("#companyNav");
	var scrollTop = 0;
	function navFixed() {
		if(scrollTop >= 286) {
			companyNav.addClass("company-nav-fixed");
		}else{
			companyNav.removeClass("company-nav-fixed");
		}
	}
	
	//滚动到某个位置公司主页侧边导航栏固定
	var silderNav = $("#myScrollspy");
	function silderFixed() {
		if(scrollTop >= 650) {
			silderNav.addClass("silder-nav");
		}else{
			silderNav.removeClass("silder-nav");
		}
	}
	
	//公司导航栏的切换
	var companyNavChange = $(".company-nav .company-nav-wrapper ul li");
	var companyNavChangeA = $(".company-nav .company-nav-wrapper ul li a");
	var infoButton = $(".info-button");
	var recruitButton = $(".recruit-button");
	var companyInfoContent = $(".section-wrapp");
	var recruitPositionContent = $(".recruit-position");
	companyNavChange.click(function() {
		companyNavChangeA.css("text-decoration","none");
		companyNavChange.removeClass("current");
		$(this).addClass("current");
		
	})
	infoButton.click(function() {
		recruitPositionContent.hide();
		companyInfoContent.show();
		silderNav.show();
	})
	recruitButton.click(function() {
		companyInfoContent.hide();
		recruitPositionContent.show();
		silderNav.hide();
	})
	
	//滚动侦听
	var section1TopDom = $("#section1").offset().top;
	var section2TopDom = $("#section2").offset().top;
	var section3TopDom = $("#section3").offset().top;
	var fixedHeight = $("#companyNav").height();
	var firstNumber = section1TopDom - 2*fixedHeight;
	var secondNumber = section2TopDom - 2*fixedHeight - 35;
	var thirdNumber = section3TopDom - 2*fixedHeight - 50;
	var rangeDom = [firstNumber,secondNumber,thirdNumber];
	var silderMenus = $("#myScrollspy ul li");
	$(window).scroll(function() {
		scrollTop = $(document).scrollTop();
		navFixed();
		silderFixed();
		if(scrollTop > firstNumber && scrollTop < secondNumber) {
			silderMenus.removeClass("active");
			silderMenus.eq(0).addClass("active");
		}
		if(scrollTop > secondNumber && scrollTop < thirdNumber) {
			silderMenus.removeClass("active");
			silderMenus.eq(1).addClass("active");
		}
		if(scrollTop > thirdNumber) {
			silderMenus.removeClass("active");
			silderMenus.eq(2).addClass("active");
		}
	})
	silderMenus.click(function() {
		var index = $(this).index();
		silderMenus.removeClass("active");
		silderMenus.eq(index).addClass("active");
		$("html,body").animate({ 
			scrollTop : rangeDom[index],
		}, 400);
		
	})
})
